package visualInterface;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.tools.JavaFileManager.Location;

public class DetailsFrame extends JFrame {
	JLabel homeTeam = new JLabel();
	JLabel awayTeam = new JLabel();

	JLabel separator1 = new JLabel("-");
	JLabel separator2 = new JLabel("-");
	JLabel separator3 = new JLabel("-");
	JLabel separator4 = new JLabel("(");
	JLabel separator5 = new JLabel("-");
	JLabel separator6 = new JLabel(")");
	JLabel separator7 = new JLabel("-");

	JLabel description1 = new JLabel("Scor la masa verde: ");
	JLabel description2 = new JLabel("Scor pe teren: ");
	JLabel description3 = new JLabel("Penalizare:");
	

	JTextField normalHomeTeamGoal = new JTextField();
	JTextField normalAwayTeamGoal = new JTextField();
	JTextField normalHalfTimeHomeTeamGoal = new JTextField();
	JTextField normalHalfTimeAwayTeamGoal = new JTextField();
	JTextField artificialHomeTeamGoal = new JTextField();
	JTextField artificialAwayTeamGoal = new JTextField();
	JTextField penaliseHomeTeam = new JTextField();
	JTextField penaliseAwayTeam = new JTextField();

	BackgroungImages mainPanel;
	GridBagLayout mainPanelLayout = new GridBagLayout();

	public void setFrame(String team1, String team2) {

		mainPanel = new BackgroungImages("details.jpg", this);
		mainPanel.setLayout(mainPanelLayout);

		
		setContentPane(mainPanel);
		setTitle(team1 + " - " + team2);
		/*
		 * try { setIconImage(ImageIO.read(new File("icon.jpg"))); } catch
		 * (IOException e) { e.printStackTrace(); }
		 */
		setFramePosition();
		homeTeam.setText(team1);
		awayTeam.setText(team2);
		setComponent();
		addFrameComponent();
	}

	private void setComponent() {
		normalHomeTeamGoal.setPreferredSize(new Dimension(20, 20));
		normalAwayTeamGoal.setPreferredSize(new Dimension(20, 20));
		normalHalfTimeHomeTeamGoal.setPreferredSize(new Dimension(20, 20));
		normalHalfTimeAwayTeamGoal.setPreferredSize(new Dimension(20, 20));
		artificialHomeTeamGoal.setPreferredSize(new Dimension(20, 20));
		artificialAwayTeamGoal.setPreferredSize(new Dimension(20, 20));
		penaliseHomeTeam.setPreferredSize(new Dimension(20, 20));
		penaliseAwayTeam.setPreferredSize(new Dimension(20, 20));

	}

	public void setFramePosition() {
		Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameDimension = new Dimension(450, 500);
		setSize(frameDimension);
		Point leftCorner = new Point();
		leftCorner.x = (screenDimension.width - frameDimension.width) / 2;
		leftCorner.y = (screenDimension.height - frameDimension.height) / 2;
		setLocation(leftCorner);
		setMinimumSize(frameDimension);
	}

	public void showFrame() {
		setVisible(true);
	}

	private void addFrameComponent() {
		GridBagConstraints c = new GridBagConstraints();

		c.insets = new Insets(3, 3, 3, 3);

		c.gridx = 1;
		c.gridy = 0;
		mainPanel.add(homeTeam, c);

		c.gridx = 2;
		mainPanel.add(separator1, c);

		c.gridx = 3;
		mainPanel.add(awayTeam, c);

		c.gridx = 0;
		c.gridy = 1;
		mainPanel.add(description1, c);

		c.gridx = 1;
		mainPanel.add(artificialHomeTeamGoal, c);

		c.gridx = 2;
		mainPanel.add(separator2, c);

		c.gridx = 3;
		mainPanel.add(artificialAwayTeamGoal, c);

		c.gridx = 0;
		c.gridy = 2;
		mainPanel.add(description2, c);

		c.gridx = 1;
		mainPanel.add(normalHomeTeamGoal, c);

		c.gridx = 2;
		mainPanel.add(separator3, c);

		c.gridx = 3;
		mainPanel.add(normalAwayTeamGoal, c);

		c.gridx = 4;
		mainPanel.add(separator4, c);

		c.gridx = 5;
		mainPanel.add(normalHalfTimeHomeTeamGoal, c);

		c.gridx = 6;
		mainPanel.add(separator5, c);

		c.gridx = 7;
		mainPanel.add(normalHalfTimeAwayTeamGoal, c);

		c.gridx = 8;
		mainPanel.add(separator6, c);

		c.gridx = 0;
		c.gridy = 3;
		mainPanel.add(description3, c);
		
		c.gridx = 1;
		mainPanel.add(penaliseHomeTeam, c);
		
		c.gridx = 2;
		mainPanel.add(separator7, c);
		
		c.gridx = 3;
		mainPanel.add(penaliseAwayTeam, c);

	}
}
